package com.uenpay.im.invokeitems.person;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.QYXUserEntity;
import com.uenpay.im.serializations.QYXUserSerializer;

import org.json.JSONObject;

/**
 * 个人资料
 *  @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class GetPersonInfoInvokeItem extends HttpInvokeItem {
	public class GetPersonInfoInvokeItemResult {
		public int status;
		public String msg;
		public QYXUserEntity user = new QYXUserEntity();
	}

	public GetPersonInfoInvokeItemResult getOutput() {
		return (GetPersonInfoInvokeItemResult) GetResultObject();
	}

	public GetPersonInfoInvokeItem() {
		String pattern = APIConfiguration.getBaseUrl() + "Cust/Cust/getCustInfo?"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(pattern);
	}

	@Override
	protected Object DeserializeResult(String responseBody) throws Exception {
		GetPersonInfoInvokeItemResult result = new GetPersonInfoInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONObject data = json.optJSONObject("data");
			if (data != null) {
				result.user = QYXUserSerializer.deserializeUser(data);
			}
		} catch (Exception e) {
			return result;
		}

		return result;
	}

}
